package com.zzy.threaddemo.newdemo;

import java.util.concurrent.Executors;

import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.RateLimiter;

public class ListenableFutureDemo {
	static ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());

	public static void main(String[] args) {

		for(int i=1;i<=5;i++){
			String theadName="线程"+i;
			// ListenableFuture顾名思义就是可以监听的Future
			ListenableFuture<String> futureTask = executorService.submit(new CallableTask(theadName));
			FutureCallbackImpl callback = new FutureCallbackImpl(theadName);
			Futures.addCallback(futureTask, callback); // 添加回调
			
			//System.out.println("callback.getCallbackResult()"+callback.getCallbackResult()); // 获取结果
		}
		
		
	}

}
